IndexOf Function

Used to search for a value in an array. Returns the index of the array element that contains the matching value.

Syntax

result = array.IndexOf( TargetValue, [StartingIndex] )


Parameters

TargetValue

The

StartingIndex (Optional)

Optional.



Example

This example uses a ComboBox that has five items in its pop-up menu that have the names of the workdays of the week. The selected day is in its Text property. This example returns the index of the array element that matches the menu selection.

Dim days() as String
days() = Array("Monday","Tuesday","Wednesday","Thursday","Friday")
Dim dayNumber as Integer
dayNumber = days.IndexOf(ComboBox1.Text)
If dayNumber >= 0 then
  MsgBox "You entered day number " + Str(dayNumber)
else
  MsgBox "You didn't enter the name of any weekday."
end if

See Also

Dim statement; Array, Join, Split, Ubound functions; Append, Array, Insert, Pop, Redim, Remove, Shuffle, Sort, Sortwith methods; ParamArray keyword.